package collection;

import java.util.Iterator;

public class HashSet<E> implements ISet<E>{

	private HashTableMap<E,E> map = new HashTableMap<E,E>();
	
	@Override
	public int size() 
	{
		return map.size();
	}

	@Override
	public boolean isEmpty() 
	{
		return map.isEmpty();
	}

	@Override
	public void add(E element) 
	{
		map.put(element, element);
	}

	@Override
	public void remove(E element) 
	{
		map.remove(element);
	}

	@Override
	public boolean contains(E element) 
	{
		return map.get(element) != null;
	}
	
	@Override
	public Iterator<E> iterator() 
	{
		return map.keys();
	}
	
	@Override
	public String toString()
	{
		String retStr = "[ ";
		Iterator<E> iter = map.keys();
		if (iter.hasNext())
		{
			retStr += iter.next();
		}
		
		while(iter.hasNext())
		{
			retStr += ", " + iter.next();
		}
		retStr += " ]";
		
		return retStr;
	}

}
